<?php


namespace App\Console\Commands;


use App\Service\Http;
use Illuminate\Console\Command;

/**
 * Class AccessToken
 * @package App\Console\Commands\AppSort
 */
class AccessToken extends Command
{
    protected $signature = 'aa';

    protected $description = 'wechat token';

    public function handle()
    {
        $this->line($this->description);

		$token = $this->getAccessToken();
		$this->line($token);

//		$url = "http://api.weixin.qq.com/wxa/msg_sec_check?cloudbase_access_token={$token}";
//		$this->line($url);


		$url = "https://api.weixin.qq.com/tcb/uploadfile?access_token={$token}";
		$this->line($url);

		$envId = $this->getEnvId();
		$path = $this->getPath();
		$data = [
			"env" => $envId,
			"path" => $path
		];

		$response = Http::post($url, $data);
		$res = $response->getBody()->getContents();
		dd($res);
    }

	/**
	 * @return string
	 */
	private function getAccessToken()
	{
		$token = readfile('/.tencentcloudbase/wx/cloudbase_access_token');
		return strval($token);

//		return 'CLwBEoACJ3yB0E1_8AmvjVDQjRxYIz7mixM2epzGG9UETcQSyElu6wew7sXyPHt0yLlydMGtV6rW8MF-4slqdDk1glLcVeppN_AEZlnzpgEP5g4jRUL8gwD6mcdkkOILtC67qLQ6zFM17KUxLLoH8PH3Ctd_1RU9rmEZb-HfXCzmTCDJWLDJylHi_G97vI7wu7UgT9FUvLmLAKca8g2_omUphz9rIH-OlZqGssFknT9Dpm8NS32y9WguHF2AvlHUDsIyq3NEKyFDo3EeCCRt-uah6X-LR62EyRDimnvaOX2phNVsACbWp6qsP22hpu5YcG2wwqmOVdMSBKdOD3wFpzWx1hcxJRgFIAA/home/WeEngine # ';
	}

	/**
	 * @return string
	 */
	private function getEnvId()
	{
//		return 'weiqing-9gf9gyjd35c4c26b';
		return getenv("CBR_ENV_ID");
	}

	/**
	 * @return string
	 */
	private function getPath()
	{
		return 'web/test';
	}
}
